/*
 * Copyright 2010 Quytelda Gaiwin
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

/*
 * AboutDialog.java
 *
 * Created on Dec 4, 2008, 4:22:19 PM
 */

package panthersleek;

import javax.swing.*;
import java.util.Locale;
import java.util.Properties;
import java.util.ResourceBundle;

/**
 * The about dialog is a dialog presented to show information pertaining the application and it's environment,
 * including the license, version number, help pages, etc.
 *
 * @author Quytelda K. Gaiwin
 */
public class AboutDialog extends javax.swing.JDialog
{

    /**
     * Creates new form AboutDialog
     *
     * @param parent The parent frame: this may be null
     * @param modal  whether or not the dialog is modal
     */
    public AboutDialog(java.awt.Frame parent, boolean modal)
    {
        super(parent, modal);
        initComponents();
        this.setResizable(false);

        //Fill the informationListLabel with information about Panther Sleek.
        //Give: version, system, architecture, homepage, license, java version
        Properties properties;

        properties = Panther.loadPantherInformation();

        //Load the values.
        String version = (String) properties.get("panther.version");
        String license_url = (String) properties.get("panther.license.url");
        String homepage = (String) properties.get("panther.site.home");
        String docURL = (String) properties.get("panther.site.help");
        String system = System.getProperty("os.name");
        String architecture = System.getProperty("os.arch");
        String java_version = System.getProperty("java.version");
        String encryptionAlgorithm = Panther.getAlgorithm();
        String digestAlgorithm = Panther.getDigestAlgorithm();

        //Show the values in the dialog.
        versionLabel.setText("Version: " + version);
        licenseLabel.setText("License: " + ResourceBundle.getBundle("panthersleek.panthersleek", Locale.getDefault()).getString("panther.about.license"));
        license_urlLabel.setText("License URL: " + license_url);
        homepageLabel.setText("Homepage: " + homepage);
        helpPageLabel.setText("Help Page: " + docURL);
        systemLabel.setText("System: " + system);
        architectureLabel.setText("Architecture: " + architecture);
        java_versionLabel.setText("Java Version: " + java_version);
        encryptionAlgorithmLabel.setText("Encryption Algorithm: " + encryptionAlgorithm);
        digestAlgorithmLabel.setText("Digest Algorithm: " + digestAlgorithm);
        langLabel.setText("Locale: " + Locale.getDefault().getDisplayLanguage() + " " + Locale.getDefault().getDisplayCountry().toUpperCase());
    }

    /**
     * This method is called from within the constructor to
     * initialize the form.
     */
    @SuppressWarnings("unchecked")
    private void initComponents()
    {

        JLabel titleLabel = new JLabel();
        license_urlLabel = new javax.swing.JLabel();
        JButton closeButton = new JButton();
        JLabel iconLabel = new JLabel();
        versionLabel = new javax.swing.JLabel();
        licenseLabel = new javax.swing.JLabel();
        systemLabel = new javax.swing.JLabel();
        architectureLabel = new javax.swing.JLabel();
        homepageLabel = new javax.swing.JLabel();
        helpPageLabel = new javax.swing.JLabel();
        encryptionAlgorithmLabel = new javax.swing.JLabel();
        digestAlgorithmLabel = new javax.swing.JLabel();
        java_versionLabel = new javax.swing.JLabel();
        JLabel summaryLabel = new JLabel();
        JSeparator separator = new JSeparator();
        langLabel = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("About");

        titleLabel.setText("<html><h1>Panther Sleek</h1></html>");

        license_urlLabel.setText("license-url");

        closeButton.setText("Close");
        closeButton.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                closeButtonActionPerformed();
            }
        });

        iconLabel.setIcon(new javax.swing.ImageIcon(this.getClass().getResource("/panthersleek/resources/logo.png"))); // NOI18N

        versionLabel.setText("[version]");

        licenseLabel.setText("license");

        systemLabel.setText("system");

        architectureLabel.setText("architecture");

        homepageLabel.setText("homepage");

        helpPageLabel.setText("helpPage");

        encryptionAlgorithmLabel.setText("encryption Algorithm");

        digestAlgorithmLabel.setText("digest Algorithm");

        java_versionLabel.setText("java-version");
        ResourceBundle bundle = ResourceBundle.getBundle("panthersleek.panthersleek", Locale.getDefault());

        summaryLabel.setText(bundle.getString("panther.about.description"));

        langLabel.setText("[language]");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(licenseLabel)
                                .addComponent(helpPageLabel)
                                .addComponent(homepageLabel)
                                .addComponent(encryptionAlgorithmLabel)
                                .addComponent(digestAlgorithmLabel)
                                .addComponent(versionLabel)
                                .addComponent(separator, javax.swing.GroupLayout.DEFAULT_SIZE, 499, Short.MAX_VALUE)
                                .addComponent(summaryLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 499, Short.MAX_VALUE)
                                .addGroup(layout.createSequentialGroup()
                                        .addComponent(titleLabel)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 279, Short.MAX_VALUE)
                                        .addComponent(iconLabel))
                                .addComponent(architectureLabel)
                                .addComponent(java_versionLabel)
                                .addComponent(systemLabel)
                                .addComponent(license_urlLabel)
                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addComponent(langLabel)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 383, Short.MAX_VALUE)
                                .addComponent(closeButton)))
                        .addContainerGap())
        );
        layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(titleLabel)
                                .addComponent(iconLabel))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(summaryLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(separator, javax.swing.GroupLayout.PREFERRED_SIZE, 16, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(versionLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(licenseLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(license_urlLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(helpPageLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(homepageLabel)
                                .addGroup(layout.createSequentialGroup()
                                .addGap(23, 23, 23)
                                .addComponent(encryptionAlgorithmLabel)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(digestAlgorithmLabel)))
                        .addGap(18, 18, 18)
                        .addComponent(architectureLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(java_versionLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(systemLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 11, Short.MAX_VALUE)
                                .addComponent(closeButton)
                                .addContainerGap())
                        .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(langLabel)
                        .addContainerGap())))
        );

        pack();
    }

    private void closeButtonActionPerformed()
    {
        this.setVisible(false);
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[])
    {
        java.awt.EventQueue.invokeLater(new Runnable()
        {
            public void run()
            {
                AboutDialog dialog = new AboutDialog(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter()
                {
                    public void windowClosing(java.awt.event.WindowEvent e)
                    {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }

    private javax.swing.JLabel architectureLabel;
    private javax.swing.JLabel digestAlgorithmLabel;
    private javax.swing.JLabel encryptionAlgorithmLabel;
    private javax.swing.JLabel helpPageLabel;
    private javax.swing.JLabel homepageLabel;
    private javax.swing.JLabel java_versionLabel;
    private javax.swing.JLabel langLabel;
    private javax.swing.JLabel licenseLabel;
    private javax.swing.JLabel license_urlLabel;
    private javax.swing.JLabel systemLabel;
    private javax.swing.JLabel versionLabel;
}
